﻿using System;

namespace ProgressViewed
{
    public enum ProgressResult { TaskComplete, Cancel }


    public interface IProgressView : IDisposable
    {
        ProgressResult ShowModal ();
        void SetMeter (int percent);
        void SetText (string message);
        void Close ();
    }


    public class ProgressModelbase : IDisposable
    {
        private IProgressView view;
        private bool disposed;

        public IProgressView View
        {
            protected get { return view; }
            set
            {
                if (view != null)
                    throw new InvalidOperationException ("View already assigned");
                view = value;
            }
        }


        public void Dispose ()
        {
            Dispose (true);
            GC.SuppressFinalize (this);
        }


        protected virtual void Dispose (bool disposing)
        {
            if (! disposed)
            {
                if (disposing)
                    view.Dispose();
                disposed = true;
            }
        }


        public string Title
        { get; protected set; }
    }
}
